//
//  SpecialInforCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/1/2.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "SpecialInforCell.h"

@interface SpecialInforCell ()

@property (weak, nonatomic) IBOutlet UIImageView *specialImageView;

@property (weak, nonatomic) IBOutlet UILabel *specailNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *guiderNameLabel;

@property (weak, nonatomic) IBOutlet UIButton *favBtn;

@end

@implementation SpecialInforCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setModel:(LineModel *)model {
    
    _model = model;
    
    [self.specialImageView setImageURL:[NSURL URLWithString:model.pictureArray.firstObject] placeholderImage:kPlaceholderSqu];
    self.specailNameLabel.text = model.linename;
    self.guiderNameLabel.text = model.guide.realname;
    
    self.favBtn.selected = model.isfavor;
}


- (IBAction)favBtnClicked:(UIButton *)sender {
    
    if (![IGUtil hasLoginOrPresentLogin]) {
        return;
    }
    
    [NetAPIManager collectWithType:CollectTypeAlbum favourid:self.model.unionid block:^(id result, NSError *error) {
        
        if (error) {
            return ;
        }
        
        BOOL isfavor = [result boolValue];
        
        self.model.isfavor = isfavor;
        
        sender.selected = !sender.selected;
        
        if (isfavor) {
            self.model.favourcount = @(self.model.favourcount.integerValue + 1).stringValue;
            [IGUtil showToast:MYLocalizedString(@"SPECAIL_FOLLOW", nil)];
            
        } else{
            
            NSInteger count = self.model.favourcount.integerValue - 1;
            if (count < 0) {
                count = 0;
            }
            self.model.favourcount = @(count).stringValue;
            [IGUtil showToast:MYLocalizedString(@"SPECAIL_FOLLOWCANCEL", nil)];
        }
    }];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
